import router from '@/router/index'
import {MessageBox} from 'element-ui'
import axios from 'axios'

router.afterEach(() => {
    axios({
        url: process.env.BASE_URL + 'version.json',
        params:{
            t: new Date().getTime()
        },
        method: 'get'
    }).then(res => {
        if(window.APP_VERSION && res.data.appVersion){
            //如果版本升级了
            if(Number(res.data.appVersion.substr(4)) > Number(window.APP_VERSION.substr(4))){
                MessageBox.alert('系统检测到版本已升级，将刷新页面更新！', '更新提示', {
                    confirmButtonText: '确定',
                    callback: action => {
                        location.reload()
                    }
                })
            }
        }
    })
});
